package commons.base.luncene;

import java.util.HashMap;
import java.util.Map;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;

public class StringDocumentBuilder {

	private Map<String, String> fieldMap = new HashMap<String, String>();
	
	public StringDocumentBuilder addField(String name, String value){
		fieldMap.put(name, value);
		return this;
	}
	
	public Document build(){
		if(fieldMap.isEmpty()){
			return null;
		}
		
		Document doc = new Document();
		
		for(Map.Entry<String, String> entry : fieldMap.entrySet()){
			doc.add(new StringField(entry.getKey(), entry.getValue(), Field.Store.YES)); 
		}
		
		return doc;
	}
}
